<body>
<h3>Workflow testing for <?php echo $workflowname;?></h3>
<p>Checkout the items.</p>
		
<div style="float:right;border:thin solid #000;padding:20px;margin-top:-70px;width:200px;color:red;">Total Price : <b><span id="total-price"></span></b></div>
<div id="products" style="padding:10px;margin:10px;border:solid thin #0FF;">

	<table>
		<tr>
			<th class="span-2">&nbsp;</th>
			<th >Name</th>
			<th >Price	</th>
		</tr>
		<tr>
			<td><input class="checkbox" model="A1" price="189" type="checkbox"/></td>
			<td>Book Reader</td>
			<td>$189</td>
		<tr>
			<td><input class="checkbox" model="A2" price="18" type="checkbox"/></td>
			<td>Book Reader Outer cover</td>
			<td>$18</td>
		</tr>
		<tr>
			<td><input class="checkbox" model="A3" price="10" type="checkbox"/></td>
			<td>Screen Protector</td>
			<td>$10</td>
		</tr>
		<tr>
			<td><input class="checkbox" model="A4" price="64" type="checkbox"/></td>
			<td>Ear phone</td>
			<td>$64</td>
		</tr>
		<tr>
			<td><input class="checkbox" model="B1" price="120" type="checkbox"/></td>
			<td>Book :: Programming in Java</td>
			<td>$120</td>
		</tr>
		<tr>
			<td><input class="checkbox" model="B2" price="89" type="checkbox"/></td>
			<td>Book :: Programming in PHP</td>
			<td>$89</td>
		</tr>
		<tr>
			<td><input class="checkbox" model="B3" price="102" type="checkbox"/></td>
			<td>Book :: Programming in ASP</td>
			<td>$102</td>
		</tr>
		<tr>
			<td><input class="checkbox" model="B4" price="74" type="checkbox"/></td>
			<td>Book :: Programming with WebServices</td>
			<td>$74</td>
		</tr>
		<tr>
			<td>&nbsp;</td>
			<td>&nbsp;</td>
			<td>&nbsp;</td>
		</tr>
		<tr>
			<td><button id="checkout-button">CheckOut</button></td>
			<td>&nbsp;</td>
			<td>&nbsp;</td>
		</tr>
	</table>
	
</div>
<script type="text/javascript">
var quantity;

function loadEventHandlers(){

	//Total Price Button
	$('#calpricebtn').button().click(function(){

		var costprice=Array();
		var i=0;
		$('.costprice').each(function(){
			costprice[i]=$(this).html();
			i++;
		});

		quantity=costprice.length;
		console.log(quantity);

		var dataString='&totaljson='+JSON.stringify(costprice);
		$.ajax({
			type: "POST",
				url: "../../../index.php/webservices/calculateTotal",
				data: dataString,
				success : function(data){
					$('#total-price').html(data);
				}
		});
		
		//Fetch the webservice
		
	});


	//Total Price Button
	$('#caltaxbtn').button().click(function(){

		var totalprice=$('#total-price').html();
		var datastring='&total='+totalprice;
		$.ajax({
			type: "POST",
				url: "../../../index.php/webservices/calculateTax",
				data: datastring,
				success : function(data){
					$('#caltaxresult').html("Tax amount of  $["+data+"]   added to the total price");

					//Fetch the webservice
					$('#total-price').html((totalprice-1 + (data-1)));
				}
		});
	
	});

	//Coupon
	//Total Price Button
	$('#couponbtn').button().click(function(){

		var coupontext='&coupontext='+$('#coupontext').val();
		var totalprice=$('#total-price').html();
		$.ajax({
			type: "POST",
				url: "../../../index.php/webservices/applyCoupon",
				data: coupontext,
				success : function(data){
					
					$('#couponresult').html("Discount of $["+data+"]   on the total price");

					//Fetch the webservice
					$('#total-price').html((totalprice-0-data));
				}
		});
	
		

	});


	$('#captchabtn').button().click(function(){

		var val=$('#captchatext').val();
		if(val == "5"){
			$('#captcharesult').html('You are right.!!');
		}else{
			$('#captcharesult').html('You are wrong.!!');

		}
			

	});


	//Gift Wrap
	$('#shipchargesbtn').button().click(function(){

		var shippingtext='&shippingtext='+$('#shippingtext').val()+'&quantity='+quantity;
		var totalprice=$('#total-price').html();

		$.ajax({
			type: "POST",
				url: "../../../index.php/webservices/shippingCharges",
				data: shippingtext,
				success : function(data){
					
					$('#shipchargesresult').html("Shipping charges  $["+data+"] for ["+quantity+"] items added to the total price");

					//Fetch the webservice
					$('#total-price').html((totalprice-1+(data-1)));
				}
		});

		
		var shippingcharge=quantity*4;
	
		$('#shipchargesresult').html("Shipping charges  $["+shippingcharge+"] for ["+quantity+"] items added to the total price");

		//Fetch the webservice
		$('#total-price').html((totalprice-0+shippingcharge));
	});


	//Gift Wrap
	$('#giftwrapbtn').button().click(function(){

		var totalprice=$('#total-price').html();

		var giftwrapamount=quantity*4;
	
		$('#giftwrapresult').html("Gift Wrap amount of  $["+giftwrapamount+"] for ["+quantity+"] items added to the total price");

		//Fetch the webservice
		$('#total-price').html((totalprice-0+giftwrapamount));
	});


	//promotion
	$('#promotionbtn').button().click(function(){
			

		
		//Fetch the webservice
		$('#promotionresult').html("Get 200 off on next purchaase");
	});

	//confirmation
	$('#confirmationbtn').button().click(function(){

		var totalprice=$('#total-price').html();
			
		
		//Fetch the webservice
		$('#confirmationresult').html("Confirmed the purchase");
	});

	$('#productsuggestbtn').button().click(function(){
		var costprice=Array();
		var i=0;
		$('.costprice').each(function(){
			costprice[i]=$(this).html();
			i++;
		});


		var dataString='&totaljson='+JSON.stringify(costprice);
		$.ajax({
			type: "POST",
				url: "../../../index.php/webservices/similiarProductSuggestions",
				data: dataString,
				success : function(data){
					$('#productsuggestresult').html(data);
				}
		});

	});


	$('#paymentbtn').button().click(function(){

		var dataString='&cctext='+$('#paymentcctext').val();
		$.ajax({
			type: "POST",
				url: "../../../index.php/webservices/makePayment",
				data: dataString,
				success : function(data){
					$('#paymentresult').html(data);
				}
		});
	});
}

$(document).ready(function(){

	$('#checkout-button').button().click(function(){
		var arr=Array();
		var i=0;
		$('.checkbox').each(function(){
			var cbox=$(this);
			if(cbox.attr('checked') == "checked" )
			{
				arr[i]=cbox.attr('model');
				i++;
			}
			
		});

		var dataString='&arrayString='+JSON.stringify(arr)+'&wfid='+<?php echo $workflowid;?>;
		$.ajax({
			type: "POST",
				url: "../../../index.php/webservices/disp",
				data: dataString,
				success : function(data){
					$('#products').html(data);
					loadEventHandlers();
				}
		});

		
	});
	

});

</script>
</body></html>